from django import forms
from django.forms import widgets, ModelForm
from .models import CustomUser


# 构造提交表单类

class CenterForm(ModelForm):
    class Meta:
        model = CustomUser
        fields = ['head', 'username', 'email', 'telephone', 'first_name', 'last_name']
        widgets = {
            'username': widgets.TextInput(attrs={
                'id': "password",
                'class': "form-control",
                'placeholder': "请输入用户名"
            }),
            'email': widgets.EmailInput(attrs={
                'id': "email",
                'class': "form-control",
                'placeholder': "请输入邮箱"
            }),
            'telephone': widgets.TextInput(attrs={
                'id': "telephone",
                'class': "form-control",
                'placeholder': "请输入电话"
            }),
            'first_name': widgets.TextInput(attrs={
                'id': "first_name",
                'class': "form-control",
                'placeholder': "请输入姓名"
            }),
            'last_name': widgets.TextInput(attrs={
                'id': "last_name",
                'class': "form-control",
                'placeholder': "请输入姓氏"
            }),
        }

class UpdatePasswordForm(forms.Form):
    password0 = forms.CharField(label="原始密码", widget=widgets.PasswordInput(attrs={
        'id': "password0",
        'class': "form-control",
        'placeholder': "请输入原始密码"
    }))
    password1 = forms.CharField(label="新密码", widget=widgets.PasswordInput(attrs={
        'id': "password1",
        'class': "form-control",
        'placeholder': "请再次输入新密码"
    }))
    password2 = forms.CharField(label="确认密码", widget=widgets.PasswordInput(attrs={
        'id': "password2",
        'class': "form-control",
        'placeholder': "请再次输入新密码"
    }))


class LoginForm(forms.Form):
    """
    label:设置人类可读的标签
    attrs:用于定义HTML元素的属性
    widget:表单控件
    """
    username = forms.CharField(label="用户名", widget=widgets.TextInput(attrs={
        'id': "username",
        'class': "form-control"
    }))
    password = forms.CharField(label="密码", widget=widgets.PasswordInput(attrs={
        'id': "password",
        'class': "form-control"
    }))


class RegisterForm(ModelForm):
    password2 = forms.CharField(label="确认密码", widget=widgets.PasswordInput(attrs={
        'id': "password2",
        'class': "form-control",
        'placeholder': "请再次输入密码"
    }))
    class Meta:
        model = CustomUser
        fields = ['username', 'password',]
        widgets = {
            'username': widgets.TextInput(attrs={
                'id': "username",
                'class': "form-control",
                'placeholder': "请输入用户名"
            }),
            'password': widgets.PasswordInput(attrs={
                'id': "password",
                'class': "form-control",
                'placeholder': "请输入密码"
            }),
            # 'email': widgets.EmailInput(attrs={
            #     'id': "email",
            #     'class': "form-control",
            #     'placeholder': "请输入邮箱"
            # }),
            # 'telephone': widgets.TextInput(attrs={
            #     'id': "telephone",
            #     'class': "form-control",
            #     'placeholder': "请输入电话"
            # }),
        }
        label = {
            'username': "用户名",
            'password': "密码",
            # 'email': "邮箱",
            # 'telephone': "电话"
        }

